package com.szbmyoubao.app.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.szbmyoubao.app.bean.ToolsItem
import com.ellecity06.common.base.BaseAdapter
import com.ellecity06.cwhiskymall.databinding.ItemToolsMenuBinding

/**
 * @author zavier
 * @time 2025/3/5 19:00
 * @des
 */
class ToolsMenuAdapter(private val block: (ToolsItem.ToolsChildItem) -> Unit) : BaseAdapter<ToolsItem, ItemToolsMenuBinding>() {
    override fun inflateBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ItemToolsMenuBinding {
        return ItemToolsMenuBinding.inflate(layoutInflater, parent, false)
    }

    override fun convert(
        binding: ItemToolsMenuBinding,
        position: Int,
        item: ToolsItem
    ) {
        binding.tvTitle.text = item.title
        binding.rvTools.layoutManager = GridLayoutManager(context, 4)
        val adapter = ToolsAdapter()
        binding.rvTools.adapter = adapter
        adapter.submitList(item.list)
        adapter.setOnItemClickListener { a, v, i ->
            val item1 = adapter.getItem(i)
            if (item1 != null)
                block.invoke(item1)
        }
    }
}